package io.rong.imkit.http

import com.custom.base.config.BaseConfig
import com.custom.base.entity.OkHttpBodyEntity
import com.custom.base.http.OkHttpFromBoy
import com.custom.base.http.OkHttpManager
import com.custom.base.http.SDOkHttpResoutCallBack
import com.sunday.eventbus.SDEventManager
import io.rong.imkit.API
import io.rong.imkit.SpName
import io.rong.imkit.entity.BaseEntity
import io.rong.imkit.entity.OpenChatEntity
import io.rong.imkit.entity.PrivateAlbumEntity
import io.rong.imkit.entity.UserModelProfileEntity
import io.rong.imkit.entity.UserProfileEntity
import io.rong.imkit.event.EnumEventTag
import io.rong.imkit.userinfo.RongUserInfoManager

object HttpRequest {


    fun getUserModelInfo(
        userCode:String,callback: RequestUserModelInfoCallBack
    ){
        OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
            override fun addBody(requestBody: OkHttpBodyEntity) {
                requestBody.setPost(API.user_model_profile_url)
                requestBody.add("userCode",userCode)
                requestBody.add("modelUserCode",BaseConfig.getInstance.getString(SpName.modelUserCode,""))
            }
        },object : SDOkHttpResoutCallBack<UserModelProfileEntity>() {
            override fun onSuccess(entity: UserModelProfileEntity) {
                callback.onSuccess(entity)
            }
        })
    }

    fun getPrivateAlbum(type:Int,callBack: RequestPrivateAlbumCallBack){
        OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
            override fun addBody(requestBody: OkHttpBodyEntity) {
                requestBody.setPost(API.user_user_albums_url)
                requestBody.add("userCode",BaseConfig.getInstance.getString(SpName.modelUserCode,""))
                requestBody.add("toUserCode",BaseConfig.getInstance.getString(SpName.modelChatUserCode,""))
                requestBody.add("albumType",type)
            }

        }, object : SDOkHttpResoutCallBack<PrivateAlbumEntity>() {
            override fun onSuccess(entity: PrivateAlbumEntity) {
                callBack.onSuccess(entity)
            }
        })
    }

    fun chatOpen(targetId:String,type:Int){
        OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
            override fun addBody(requestBody: OkHttpBodyEntity) {
                requestBody.setPost(API.user_chat_open_url)
                requestBody.add("userCodeFriend", targetId)
                requestBody.add("modelUserCode",BaseConfig.getInstance.getString(SpName.modelUserCode,""))
                requestBody.add("type", type)


            }
        }, object : SDOkHttpResoutCallBack<OpenChatEntity>() {
            override fun onSuccess(entity: OpenChatEntity) {
            }

            override fun onFailure(code: Int, msg: String) {
            }
        })
    }

    fun commonNotify(source:String,content:String){
        try {
            if (BaseConfig.getInstance.getBoolean(SpName.openNotify,true)) {
                OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
                    override fun addBody(requestBody: OkHttpBodyEntity) {
                        requestBody.setGet(API.user_common_notify_url+"/"+BaseConfig.getInstance.getString("userCode", ""))
                        requestBody.add("source", source)
                        requestBody.add("name", content)
                    }
                }, object : SDOkHttpResoutCallBack<BaseEntity>(false) {
                    override fun onSuccess(entity: BaseEntity) {
                    }
                })
            }
        }catch (e:Exception){

        }

    }


    interface RequestCallBack{
        fun onSuccess()
        fun onFailure(code: Int, msg: String)
    }
    interface RequestSuccessCallBack{
        fun onSuccess()
    }

    interface RequestTurnOnsSuccessCallBack{
        fun onSuccess(entity: OpenChatEntity.Data)
    }
    interface RequestUserInfoCallBack{
        fun onSuccess(entity:UserProfileEntity)
    }

    interface RequestUserModelInfoCallBack{
        fun onSuccess(entity:UserModelProfileEntity)
    }
    interface RequestPrivateAlbumCallBack{
        fun onSuccess(entity:PrivateAlbumEntity)
    }
}